#include "Cmd_Draw.h"

HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

void Set_Color(int color)
{
	SetConsoleTextAttribute(hOut, color); 
}

void Set_Size()
{
    COORD size = {4000, 4000};
    SetConsoleScreenBufferSize(hOut,size); 
    SMALL_RECT rc = {0,0, 4000-1,4000-1}; 
    SetConsoleWindowInfo(hOut,true ,&rc);
}

void Set_Grapics(int x, int y ,int color)
{
    Set_Color(color);
	COORD pos;
	pos.X = x; 
	pos.Y = y; 
	SetConsoleCursorPosition(hOut, pos);
	Sleep(1); //for demenstrating
}


void cls(HANDLE hConsole)
{
   CONSOLE_SCREEN_BUFFER_INFO csbi;
   SMALL_RECT scrollRect;
   COORD scrollTarget;
   CHAR_INFO fill;

   // Get the number of character cells in the current buffer.
   if (!GetConsoleScreenBufferInfo(hConsole, &csbi))
   {
       return;
   }

   // Scroll the rectangle of the entire buffer.
   scrollRect.Left = 0;
   scrollRect.Top = 0;
   scrollRect.Right = csbi.dwSize.X;
   scrollRect.Bottom = csbi.dwSize.Y;

   // Scroll it upwards off the top of the buffer with a magnitude of the entire height.
   scrollTarget.X = 0;
   scrollTarget.Y = (SHORT)(0 - csbi.dwSize.Y);

   // Fill with empty spaces with the buffer's default text attribute.
   fill.Char.UnicodeChar = TEXT(' ');
   fill.Attributes = csbi.wAttributes;

   // Do the scroll
   ScrollConsoleScreenBuffer(hConsole, &scrollRect, NULL, scrollTarget, &fill);

   // Move the cursor to the top left corner too.
   csbi.dwCursorPosition.X = 0;
   csbi.dwCursorPosition.Y = 0;

   SetConsoleCursorPosition(hConsole, csbi.dwCursorPosition);
}


void Clear_Grapics()
{
	cls(hOut);
}